﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Issues.IssueQuestTasks.ChangeCommonAreaOwnerQuestTask
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Issues.IssueQuestTasks
{
  public class ChangeCommonAreaOwnerQuestTask : QuestTaskBase
  {
    [SaveableField(20)]
    private readonly Alley _alley;
    [SaveableField(21)]
    private readonly Hero _newOwner;
    private readonly Action _onAlleyCapturedByPlayer;
    private readonly Action _onAlleyClearedButNotGivenToQuestGiver;
    private readonly Action _onAlleyGivenToTarget;

    internal static void AutoGeneratedStaticCollectObjectsChangeCommonAreaOwnerQuestTask(
      object o,
      List<object> collectedObjects)
    {
      ((QuestTaskBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._alley);
      collectedObjects.Add((object) this._newOwner);
    }

    internal static object AutoGeneratedGetMemberValue_alley(object o)
    {
      return (object) ((ChangeCommonAreaOwnerQuestTask) o)._alley;
    }

    internal static object AutoGeneratedGetMemberValue_newOwner(object o)
    {
      return (object) ((ChangeCommonAreaOwnerQuestTask) o)._newOwner;
    }

    public ChangeCommonAreaOwnerQuestTask(
      Alley alley,
      Hero newOwner,
      Action onSucceededAction,
      Action onFailedAction,
      Action onCanceledAction,
      Action onAlleyCapturedByPlayer,
      Action onAlleyClearedButNotGivenToQuestGiver,
      DialogFlow dialogFlow = null)
      : base(dialogFlow, onSucceededAction, onFailedAction, onCanceledAction)
    {
      this._alley = alley;
      this._newOwner = newOwner;
      this._onAlleyCapturedByPlayer = onAlleyCapturedByPlayer;
      this._onAlleyClearedButNotGivenToQuestGiver = onAlleyClearedButNotGivenToQuestGiver;
      this._onAlleyGivenToTarget = onSucceededAction;
    }

    public void OnCommonAreaOwnerChanged(Alley alley, Hero newOwner, Hero oldOwner)
    {
      if (this._alley != alley)
        return;
      if (this._newOwner == newOwner && newOwner == Hero.MainHero)
      {
        this.Finish(QuestTaskBase.FinishStates.Success);
      }
      else
      {
        if (newOwner != Hero.MainHero || this._onAlleyCapturedByPlayer == null)
          return;
        this._onAlleyCapturedByPlayer();
      }
    }

    public override void SetReferences()
    {
      CampaignEvents.AlleyOwnerChanged.AddNonSerializedListener((object) this, new Action<Alley, Hero, Hero>(this.OnCommonAreaOwnerChanged));
    }
  }
}
